/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.own.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.own.entity.OwnOutInformation;
import com.jeesite.modules.own.service.OwnOutInformationService;

import java.util.List;

/**
 * 出库信息Controller
 * @author F
 * @version 2019-09-27
 */
@Controller
@RequestMapping(value = "${adminPath}/own/ownOutInformation")
public class OwnOutInformationController extends BaseController {

	@Autowired
	private OwnOutInformationService ownOutInformationService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public OwnOutInformation get(String id, boolean isNewRecord) {
		return ownOutInformationService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("own:ownOutInformation:view")
	@RequestMapping(value = {"list", ""})
	public String list(OwnOutInformation ownOutInformation, Model model) {
		model.addAttribute("ownOutInformation", ownOutInformation);
		return "modules/own/ownOutInformationList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("own:ownOutInformation:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<OwnOutInformation> listData(OwnOutInformation ownOutInformation, HttpServletRequest request, HttpServletResponse response) {
		ownOutInformation.setPage(new Page<>(request, response));
		Page<OwnOutInformation> page = ownOutInformationService.findPage(ownOutInformation);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("own:ownOutInformation:view")
	@RequestMapping(value = "form")
	public String form(OwnOutInformation ownOutInformation, Model model) {
		model.addAttribute("ownOutInformation", ownOutInformation);
		return "modules/own/ownOutInformationForm";
	}

	/**
	 * 保存出库信息
	 */
	@RequiresPermissions("own:ownOutInformation:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated OwnOutInformation ownOutInformation) {
		ownOutInformationService.save(ownOutInformation);
		return renderResult(Global.TRUE, text("保存出库信息成功！"), ownOutInformation);
	}
	
	/**
	 * 删除出库信息
	 */
	@RequiresPermissions("own:ownOutInformation:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(OwnOutInformation ownOutInformation) {
		ownOutInformationService.delete(ownOutInformation);
		return renderResult(Global.TRUE, text("删除出库信息成功！"));
	}

	/**
	 * 根据父级ID查询出库信息
	 * @param contentsId
	 * @return
	 */
	@RequiresPermissions(value = {"own:ownOutInformation:view","own:ownOutContents:view"}, logical = Logical.OR)
	@RequestMapping(value = "findByContentsId")
	@ResponseBody
	public String findByContentsId(String contentsId) {
		return renderResult(Global.TRUE, text("查询出库信息成功！"), ownOutInformationService.findByContentsId(contentsId));
	}
	
}